package com.hades.xq.single.java;

/**
 * 双重检测式
 * <p>
 * 优点:第一次获取的时候才会加锁
 * 缺点:写法有点难，考点记性
 */
public class DoubleCheckSingleton {
    //第一步：私有构造
    private DoubleCheckSingleton() {

    }

    //第二步：创建静态对象
    private static volatile DoubleCheckSingleton INSTANCE;

    //第三步：对外公开获取方法
    public static DoubleCheckSingleton getInstance() {
        if (INSTANCE == null) {
            synchronized (DoubleCheckSingleton.class) {
                if (INSTANCE == null) {
                    INSTANCE = new DoubleCheckSingleton();
                }
            }
        }
        return INSTANCE;
    }
}